package gov.pbc.nn.kjgl.maintenance.handler;

import gov.pbc.nn.core.dao.CommonJdbcDao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import com.bstek.uflo.env.Context;
import com.bstek.uflo.model.ProcessInstance;
import com.bstek.uflo.process.handler.AssignmentHandler;
import com.bstek.uflo.process.node.TaskNode;

/**
 * 系统运维人员
 * 
 * @author Administrator
 * 
 */
@Component(SysOperatorAssignmentHandler.BEAN_ID)
public class SysOperatorAssignmentHandler implements AssignmentHandler {

	public static final String BEAN_ID = "gov.pbc.nn.kjgl.maintenance.handler.SysOperatorAssignmentHandler";

	@Resource(name = CommonJdbcDao.BEAN_ID)
	private CommonJdbcDao jdbcDao;

	@Override
	public Collection<String> handle(TaskNode node, ProcessInstance pi,
			Context context) {
		String sysId = (String) context.getProcessService().getProcessVariable(
				"sysId", pi);
		List<String> users = this.getOperators(sysId);
		return users;
	}

	/**
	 * 获取运维人员
	 * 
	 * @param sysId
	 * @return
	 */
	public List<String> getOperators(String sysId) {
		String sql = "select s.USERNAME_,s.CNAME_ from t_sys_operation_staff s where s.SYS_ID_=? and s.INVALID_=0";
		List<String> users = this.jdbcDao.getJdbcTemplate().query(sql,
				new Object[] { sysId }, new RowMapper<String>() {

					@Override
					public String mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						String username = rs.getString("USERNAME_");
						return username;
					}

				});
		return users;
	}
}
